#ifndef __SPACEDEFENDER_GameConsole_H__
#define __SPACEDEFENDER_GameConsole_H__

#include <list>
#include <map>
#include <vector>
#include "Ogre.h"
#define OIS_DYNAMIC_LIB
#include <OIS/OIS.h>

namespace spacedefender
{

class GameConsole 
{
	public:
		static GameConsole* GetInstance();
		virtual void SetVisible(const bool visible);
		virtual const bool IsVisible() const;
		virtual void Init(Ogre::Root* root);
		virtual void Shutdown();
		
		virtual bool update(const Ogre::FrameEvent &evt);
		//virtual bool frameStarted(const Ogre::FrameEvent &evt);
		//virtual bool frameEnded(const Ogre::FrameEvent &evt);
		
		virtual void onKeyPressed(const OIS::KeyEvent &arg);
		
		void AddCommand(const Ogre::String &command, void (*)(std::vector<Ogre::String>&));
		void RemoveCommand(const Ogre::String &command);
		void ClearConsole();
	private:
		virtual void print(const Ogre::String &text);
		GameConsole();
		virtual ~GameConsole();
		
		bool _visible;
		Ogre::Root* _root;
		Ogre::SceneManager* _sceneMgr;
		Ogre::SceneNode* _sceneNode;
		Ogre::OverlayElement* _textbox;
		Ogre::Overlay* _overlay;
		Ogre::Rectangle2D* _rect;
		
		bool _update_overlay;
		float _height;
		int _start_line;
		std::list<Ogre::String> _lines;
		Ogre::String _prompt;
		std::map<Ogre::String,void (*)(std::vector<Ogre::String>&)> _commands;
		
		const int CONSOLE_LINE_LENGTH;
		const int CONSOLE_LINE_COUNT;
		
		static GameConsole _gameConsole;
		
};

}
#endif // __SPACEDEFENDER_GameConsole_H__
